package com.example.supermarket.mapper;

import com.example.supermarket.entity.Card;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * <p>卡表映射器<p/>
 *
 * @Author: porridge
 * @Date:2021/10/8 19:35
 */
@Mapper
@Repository
public interface CardMapper {

    /**
     * <p>插入卡信息<p/>
     */
    @Insert("insert into card values (default, #{cardId}, #{grade})")
    int insert(@Param("cardId") String cardId, @Param("grade") int grade);

    /**
     * <p>删除卡<p/>
     */
    @Delete("delete from card where id=#{id}")
    int delete(@Param("id") int id);

    /**
     * <p>根据id修改卡<p/>
     */
    @Update("update card set grade=#{grade} where id=#{id}")
    int updateById(@Param("id") int id, @Param("grade") int grade);

    /**
     * <p>查找全部卡信息<p/>
     */
    @Select("select id, card_id, grade from card order by id desc")
    List<Card> findAll();

    /**
     * 根据会员卡号查找卡信息
     */
    @Select("select id, card_id, grade from card where card_id=#{cardId}")
    Card findByCardId(@Param("cardId") String cardId);

    /**
     * 根据id查找卡信息
     */
    @Select("select id, card_id, grade from card where id = #{id}")
    Card findById(@Param("id") int id);

}
